/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { Work } from '../../../../../src/base/internal/pool/model/work';
import { Priority } from '../../../../../src/base/internal/pool/enum/priority';
import { TCB } from '../../../../../src/base/internal/pool/model/tcb';
import { noop } from '../../../../../src/common/util/noop';
import { TaskState } from '../../../../../src/base/internal/pool/enum/task-state';
import { ITCB } from '../../../../../src/base/internal/pool/model/itcb';

describe('test tcb', () => {
  const work = new Work(Priority.FIRST, undefined, '');
  test('test setState', () => {
    const tcb: ITCB = new ITCB(work, noop, false, [], () => {
      // empty
    }, '', '', '');
    expect(tcb.setState(TaskState.WAITING)).toBeFalsy();
    expect(tcb.setState(TaskState.RUNNING)).toBeTruthy();
  });

  test('test setPriority', () => {
    const tcb: ITCB = new ITCB(work, noop, false, [], () => {
      // empty
    }, '', '', '');
    expect(tcb.setPriority(Priority.FIRST)).toBeTruthy();
    tcb.setState(TaskState.RUNNING);
    expect(tcb.setPriority(Priority.FIRST)).toBeFalsy();
  });

  test('test setCallback', () => {
    const tcb: ITCB = new ITCB(work, noop, false, [], () => {
      // empty
    }, '', '', '');
    expect(tcb.setCallback(noop)).toBeTruthy();
    tcb.setState(TaskState.REJECT);
    expect(tcb.setCallback(noop)).toBeFalsy();
  });

  test('test setStartTime', () => {
    const tcb: ITCB = new ITCB(work, noop, false, [], () => {
      // empty
    }, '', '', '');
    const time = Date.now();
    tcb.setStartTime(time);
    expect(tcb.getStartTime() === time).toBeTruthy();
  });

  test('test setEndTime', () => {
    const tcb: ITCB = new ITCB(work, noop, false, [], () => {
      // empty
    }, '', '', '');
    const time = Date.now();
    tcb.setEndTime(time);
    expect(tcb.getEndTime() === time).toBeTruthy();
  });
});
